package com.lagou.filter;

import com.lagou.common.Common;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author banzijian
 * @date 2020/10/23
 **/
@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        long start = System.currentTimeMillis();

        Result result = invoker.invoke(invocation);

        long end = System.currentTimeMillis();

        Long usedTime = end - start;

        String methodName = invocation.getMethodName();

        Common.put(methodName, usedTime);
        // 执行方法
        return result;
    }
}
